package com.example.demo11;

import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.mitre.dsmiley.httpproxy.ProxyServlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyProxy extends ProxyServlet {

    protected HttpResponse doExecute(HttpServletRequest servletRequest, HttpServletResponse servletResponse, HttpRequest proxyRequest) throws IOException, IOException {
        super.doLog = false;//关闭父类的日志输出
        proxyRequest.setHeader("Authorization", "Basic " + "aaaaa");
        HttpResponse response = super.doExecute(servletRequest, servletResponse, proxyRequest);
        String ip = IpUtil.getIpAddress(servletRequest);
        System.out.println("这里进行权限控制和输出日志。。。。。。。。。。。，ip：" + ip + servletRequest.getMethod() + " uri: " + " -- " + proxyRequest.getRequestLine().getUri());


//    设置跨域，暂时不用。
//    String origin = servletRequest.getHeader("origin");
//    response.setHeader("Access-Control-Allow-Origin", origin);
//     response.setHeader("Access-Control-Allow-Credentials", "true");
//    response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
//    response.setHeader("Access-Control-Allow-Headers",
//        "Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin" +
//            ",User-Agent,X-Mx-ReqToken,X-Requested-With");
        return response;
    }


}
